package com.zhejiangzhengyuan.municipal_common.mapper;

import com.zhejiangzhengyuan.municipal_common.entity.UserInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhejiangzhengyuan.municipal_common.entity.vo.UsernameVo;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户表，用于存储平台内所有用户数据 Mapper 接口
 *
 * @author linju
 * @since 2019-11-22
 */
@Repository
public interface UserInfoMapper extends BaseMapper<UserInfo> {

  @Select(
      "select ui.username,ui.id\n"
          + "            from department d,user_info ui,department_user_info_mapping dui \n"
          + "            WHERE dui.department_id = d.id and dui.user_info_id=ui.id and name='路桥巡检组'")
  List<UsernameVo> usernameVo();

  @Select(
      "select u.* from subject s,user_info u,subject_user_info_mapping sum where s.id=sum.subject_id and  sum.user_info_id=u.id and s.id=#{sid}")
  UserInfo selectUserInfoIdBySubject(@Param("sid") Long sid);

  @Select(
      "select ui.* from department d,user_info ui,department_user_info_mapping dui WHERE dui.user_info_id = ui.id and dui.department_id = d.id and d.name=#{departmentName}")
  List<UserInfo> getUsersByDepartmentName(@Param("departmentName") String departmentName);
}
